﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NextCMS.Models;

public partial class Process : WebadminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Cache.SetNoStore();
        string function=Convert.ToString(Request["funcation"]);
        if (!String.IsNullOrEmpty(function))
        {
            switch(function)
            {
                case "ADDMODULE":
                    AddNewModule();
                    break;
                
                case "GetSubModules":
                    GetSubModules();
                    break;
                case "RemoveModule":
                    RemoveModule();
                    break;
                default:
                    return;
            }
            
        }
    }
    void RemoveModule()
    {
        int PageModuleId = Convert.ToInt32(Request["PageModuleId"]);
        PageModulesHelper pmc = new PageModulesHelper();
        pmc.Delete(PageModuleId);
    }
    void GetSubModules()
    {
        int ModuleId = Convert.ToInt32(Request["ModuleId"]);
        ModulesHelper mc = new ModulesHelper();
        System.Web.Script.Serialization.JavaScriptSerializer oSerializer = 
         new System.Web.Script.Serialization.JavaScriptSerializer();
        string sJSON = oSerializer.Serialize(mc.GetById(ModuleId).SubModules);
        Response.Clear();
        Response.Write(sJSON);
        Response.End();
    }
    
    void AddNewModule()
    {
        int ModuleId = Convert.ToInt32(Request["ModuleId"]);
        int SubModuleId = Convert.ToInt32(Request["SubModuleId"]);
        
        PageModulesHelper pm = new PageModulesHelper();
        PageModuleModel pmm = new PageModuleModel();
        pmm.ModuleId = ModuleId;
        pmm.SubModuleId = SubModuleId;
        pmm.PageId = Convert.ToInt32(Request["PageId"]);
        pmm.SectionId = new Guid(Convert.ToString(Request["SectionId"]));
        pmm.DisplayOrder = 1;
        pmm.LanguageId = UserLanguageId;
        pmm.RefId = 0;
        pm.Save(pmm);

        Response.Clear();
        Response.Write("");
        Response.End();
    }
}